#include<iostream>
#include<sys/types.h>
#include<sys/wait.h>
#include<unistd.h>
using namespace std;

int main()
{
    pid_t id = fork();

    //子进程
    if(id == 0)
    {
        int n = 5;
        while(n--)
        {
            cout << "i am child process" << endl;
            sleep(1);
        }
    }
    else if(id > 0)
    {
        //父进程
        int status;
        pid_t wd = waitpid(-1,&status,0);
        if(WIFEXITED(status))
        {
            cout << "i am father process, process status: " << WEXITSTATUS(status)<< endl;
            cout << "core dump :" << ((status & 0x80) >> 7) << endl;
        }
        else
        {
            cout << "wait failed" << endl;
        }
    }


    return 0;
}